package en.ameen.preciousengine;

import java.util.LinkedList;
import java.util.Queue;

/*!
This class is a special type of queue that holds the events initiated by the user; 
for the time being the engine will supply you with a single event in each frame. 
So in the best times when your game runs in 60fps your game will handle 60 events 
per second, which is pretty reasonable.
*/
public class EventQueue {

	//! The actual queue
	private static Queue<EventPacket> events;
	
    //! Function to initialize the queue
	public static void initializeQueue(){
		
		events = new LinkedList<EventPacket>();
		
	}
	
    //! Function that pushes the event in the queue
    /*!
      This will push event in the queue
      \param packet input packet to be pushed in the queue

    */
	public static void pushEvent(EventPacket packet){
		
		if (packet != null)
		events.add(packet);
		
	}
	
	
    //! Function that will return an event from the queue
    /*!
      
      \return event from queue

    */
	public static EventPacket grabEvent(){
		
		if (events.size() > 0)
		
			return (EventPacket)events.poll();
		
		else
		
			
			return null;
		
	}
	
    //! Function that checks if the queue is empty
    /*!
   
      \return Flag the indicate if the queue is empty

    */
	public static boolean isEmpty(){
		
		return (events.size() == 0);
			
	}
	
    //! Function that return how many events are there in the queue
    /*!
     
      \return Events count in the queue

    */
	public static int size(){
		
		return (events.size());
			
	}
	
	

}
